﻿using Grpc.Core;
using MagicOnion.Client;
using RPCTestShared;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RPCClient
{
    class Program
    {
        static async Task Main(string[] args)
        {
            // standard gRPC channel
            var channel = new Channel("localhost", 12345, ChannelCredentials.Insecure);

            // get MagicOnion dynamic client proxy
            var client = MagicOnionClient.Create<IMyFirstService>(channel);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int i = 0; i < 10000; i++)
            {
                // call method.
                var result = await client.SumAsync(100, 200);

                //Console.WriteLine("result:{0}", result);

                var point = new ProjectPoint();
                point.ProjectId = Guid.NewGuid().ToString();
                point.ProjectName = "PN";
                var data = await client.CreateProjectData(point);

                //Console.WriteLine($"data {data.Title}  {data.ModifyTime}");
            }
            sw.Stop();

            Console.WriteLine("执行10000次，花费：{0} milliseconds", sw.ElapsedMilliseconds); //10秒

            Console.ReadKey();

        }
    }
}
